﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
//using System.Xml.Linq;
using System.Data;
using KPIS.Utils;
using KPIS.DBM;
using KPIS.GERP.GHRMS.IBLL;
using KPIS.GERP.GHRMS.BLL;
using KPIS.GERP.GHRMS.MODEL;
using Telerik.Web.UI;


namespace KPIS.GERP.GHRMS.APP.App_UI.UserControls
{
    public partial class TR_TrainingCourses : System.Web.UI.UserControl
    {
        private object _dataItem = null;
        HR_Development iniData = new HR_Development();
        InitialData_BLL iniDataCur = new InitialData_BLL();
        ITrainingScholarshipFundBLL SchFundBLL = new TrainingScholarshipFundBLL();
        ComboBLL combo = new ComboBLL();
        TrainingInstituteBLL InstituteBLL = new TrainingInstituteBLL();

        //ReadOnly property.
        public object DataItem
        {
            get
            {
                return this._dataItem;
            }
            set
            {
                this._dataItem = value;
            }
        }
        protected bool IsUserControlPostBack
        {
            get
            {
                return this.ViewState["IsUserControlPostBack"] != null;
            }
        }
        //Initializing the new variable updating ViewState data.
        protected override void OnLoad(System.EventArgs e)
        {
            base.OnLoad(e);

            if (!IsUserControlPostBack)
            {
              
                this.ViewState.Add("IsUserControlPostBack", true); 
                bindCommandType();
                CBTrainingCur();
                DDLScholarFundID();
                DDLBgmSource();
                DDLTrainingGroup();
                DDLTInstitute();
            }          

            if (DataItem != null)
            {
                if (!(DataItem is Telerik.Web.UI.GridInsertionObject))
                {
                    lblID.Text = DataBinder.Eval(DataItem, "tran_seq").ToString();
                    cbTrainingCur.SelectedValue = DataBinder.Eval(DataItem, "training_cur_seq").ToString();
                    txtRefNo.Text = DataBinder.Eval(DataItem, "ref_no").ToString();
                    txtTrainingCourseDescr.Text = DataBinder.Eval(DataItem, "training_course_descr").ToString();
                    //txtTrainingInsID.Text = DataBinder.Eval(DataItem, "training_ins_seq").ToString();
                    ddlScholarFundID.SelectedValue = DataBinder.Eval(DataItem, "scholar_fund_seq").ToString();
                    //ddlBgSource.SelectedValue = DataBinder.Eval(DataItem, "bg_source_seq").ToString();
                    ddlTrainingGroup.SelectedValue = DataBinder.Eval(DataItem, "training_group_seq").ToString();
                    txtEmpPreCon.Text = DataBinder.Eval(DataItem, "epc_seq").ToString();
                    //txtDateSignStart.Text = DataBinder.Eval(DataItem, "date_sign_start").ToString();
                    //txtDateSignEnd.Text = DataBinder.Eval(DataItem, "date_sign_end").ToString();
                    //txtDateTrainingStart.Text = DataBinder.Eval(DataItem, "date_training_start").ToString();
                    //txtDateTrainingEnd.Text = DataBinder.Eval(DataItem, "date_training_end").ToString();
                    txtMaxTraineeCount.Text = DataBinder.Eval(DataItem, "max_trainee_count").ToString();
                    txtTotalPrice.Text = DataBinder.Eval(DataItem, "total_price").ToString();
                    txtSchedule.Text = DataBinder.Eval(DataItem, "schedule_text").ToString();
                    ddlCountry.SelectedValue = DataBinder.Eval(DataItem, "country_seq").ToString();

                    cbTrainingCur.SelectedValue = DataBinder.Eval(DataItem, "training_cur_seq").ToString();
                    cbTrainingCur.SelectedValue = DataBinder.Eval(DataItem, "training_cur_seq").ToString();
                    //txtNameShort.Text = DataBinder.Eval(DataItem, "ext_name_short").ToString();
                    //txtExtAmount.Text = DataBinder.Eval(DataItem, "ext_amount", "{0:N2}").ToString();
                    //string  = DataBinder.Eval(DataItem, "internal").ToString();
                    //if (inter == "1")
                    //    rdoInternal.Items[0].Selected = true;
                    //else
                    //    rdoInternal.Items[1].Selected = true;
                    //string local = DataBinder.Eval(DataItem, "local").ToString();
                    //if (local == "1")
                    //    rdoLocal.Items[0].Selected = true;
                    //else
                    //    rdoLocal.Items[1].Selected = true;
                    txtRemark.Text = DataBinder.Eval(DataItem, "remarks").ToString();
                    txtTotalScore.Text = DataBinder.Eval(DataItem, "total_score").ToString();
                    txtScoreVeryGood.Text = DataBinder.Eval(DataItem, "score_very_good").ToString();
                    txtScoreGood.Text = DataBinder.Eval(DataItem, "score_good").ToString();
                    txtScoreAcceptable.Text = DataBinder.Eval(DataItem, "score_acceptable").ToString();
                    //ddlStatusRec.SelectedValue = DataBinder.Eval(DataItem, "record_status").ToString();
                    //txtRemarks.Text = DataBinder.Eval(DataItem, "remarks").ToString();
                    this.btnAddnew.Visible = false;
                    this.btnUpdate.Visible = true;
                }
                else
                {
                    this.btnUpdate.Visible = false;
                    this.btnAddnew.Visible = true;
                    //lblID.Text = Session["training_type_seq"].ToString();
                                    }
            }
         

        }

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnAddnew_Click(object sender, EventArgs e)
        {
           /*try
            {
                iniData.InsertTrainingCourses(txtRefNo.Text, txtTrainingCourseDescr.Text,txtTrainingInsID.Text
                                            , ddlScholarFundID.SelectedValue //,ddlBgSource.SelectedValue
                                            , ddlTrainingGroup.SelectedValue, txtEmpPreCon.Text, txtDateSignStart.Text
                                            , txtDateSignEnd.Text , txtDateTrainingStart.Text, txtDateTrainingEnd.Text
                                            , txtMaxTraineeCount.Text , Convert.ToInt32(txtTotalPrice.Text), txtSchedule.Text, ddlCountry.SelectedValue
                                            , txtRemark.Text,"",Convert.ToInt32(txtTotalScore.Text), Convert.ToInt32(txtScoreVeryGood.Text)
                                            , Convert.ToInt32(txtScoreGood.Text), Convert.ToInt32(txtScoreAcceptable.Text)
                                            , rblScoreType.SelectedValue,"1"); 
              
            catch(Exception ex)
            {
                
            }*/
        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            try
            {
                //iniData.UpdateTrainingTypes(lblID.Text, txtName.Text,ddlCountry.SelectedValue,"1",rdoInternal.SelectedValue,rdoLocal.SelectedValue);
            }
            catch (Exception ex)
            {

            }
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {

        }

        protected void DDLBgmSource()
        {

            ddlBgmSource.DataSource = iniDataCur.ListBgmSource("");
            ddlBgmSource.DataBind();
        }

        protected void DDLScholarFundID()
        {
            ddlScholarFundID.DataSource = SchFundBLL.GetFull();
            ddlScholarFundID.DataBind();
        }
        private void CBTrainingCur()
        {
            cbTrainingCur.DataSource = iniDataCur.ListTrainingCurriculums("");
            cbTrainingCur.DataBind();
        }

        private void bindCommandType()
        {
            DataTable InfoList = combo.ListCountries();

            ddlCountry.DataSource = InfoList;
            ddlCountry.DataBind();
        }
        private void DDLTrainingGroup()
        {
            ddlTrainingGroup.DataSource = iniDataCur.ListTrainingGroup("");
            ddlTrainingGroup.DataBind();
        }
        private void DDLTInstitute()
        {
            ddlInstitute.DataSource = InstituteBLL.GetFull();
            ddlInstitute.DataBind();
        }
    }
}